﻿using Gym.Application.Reservations.Commands.CreateReservation;
using Gym.Contracts.Reservations;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Gym.Api.Controllers
{
    [Route("sessions/{sessionId:guid}/reservations")]
    public class ReservationsController : ApiController
    {
        private ISender _sender;

        public ReservationsController(ISender sender)
        {
            _sender = sender;
        }

        [HttpPost]
        public async Task<IActionResult> CreateReservation(
            CreateReservationRequest request,
            Guid sessionId)
        {
            var command = new CreateReservationCommand(
                sessionId,
                request.ParticipantId);

            var createReservationResult = await _sender.Send(command);

            return createReservationResult.Match(_ => NoContent(), Problem);
        }
    }
}
